package com.zk.ppa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zk.ppa.dao.po.FamilyMembers;
import com.zk.ppa.dao.repository.FamilyMembersRepository;
import com.zk.ppa.service.FamilyMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mr.yang
 * @create 2021-03-24 22:28
 */
@Service
public class FamilyMemberServiceImpl implements FamilyMemberService {
    @Autowired
    private FamilyMembersRepository familyMembersRepository;


    @Override
    public Boolean saveFamilyMember(List<FamilyMembers> familyMembers) {
        return familyMembersRepository.saveBatch(familyMembers);
    }

    @Override
    public List<FamilyMembers> getFamilyMembers(long family_id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.ge("family_id", family_id);
        return familyMembersRepository.list(queryWrapper);
    }

    @Override
    public Boolean updateFamilyMembersById(FamilyMembers familyMembers) {
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.ge("name", familyMembers.getName());
        wrapper.ge("state_id", familyMembers.getStateId());
        wrapper.ge("gender", familyMembers.getGender());
        wrapper.ge("identity", familyMembers.getIdentity());
        wrapper.ge("relationship_id", familyMembers.getRelationshipId());
        wrapper.ge("family_id", familyMembers.getFamilyId());
        return familyMembersRepository.update(wrapper);
    }

    @Override
    public Boolean deleteFamilyMembersById(long family_id, long Id) {
        QueryWrapper<FamilyMembers> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("famliy_id", family_id).ge("Id", Id);
        return familyMembersRepository.remove(queryWrapper);
    }
}
